package com.thread.www;

import java.util.concurrent.BlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author 新技术软件：汪洋
 */
public class MonitorThreadPoolExecutor extends ThreadPoolExecutor{
    public MonitorThreadPoolExecutor(int arg0 , int arg1 , int arg2 , TimeUnit arg3 , BlockingDeque<Runnable> arg4){
        super(arg0 , arg1 , arg2 , arg3 , arg4);
    }

    protected  void beforeExecute(Thread t , Runnable r){
        super.beforeExecute(t , r);
        System.out.println("work_task afer thread is :" + r );
    }


    protected void afterExecute(Runnable r , Throwable t){
        super.afterExecute(r , t);
        System.out.println("work_task afer thread is :" + r );
    }

    /**
     * taskCount 线程池需要执行的任务数量
     * copletedTaskCount 线程池在运行过程中已经完成的任务数量，小于或等于taskCount
     * LargestPoolSize 线程池曾经创建过的最大线程数量，通过这个数量可以知道线程是否满过 ，等于最大数量的话，表示曾经出现过满负载的情况
     * getPoolSize,线程池的线程数量，如果线程池不销毁的话，线程也不会自动销毁，所以这个大小只会增加不会减少
     * getActiveCount 获取活动的线程数
     */
    protected void terminated(){
        System.out.println("termined getCorePoolSize : " + this.getCorePoolSize() + " getPoolSize : " + this.getPoolSize() + " getTaskCount : " + this.getTaskCount() +
            "getCompletedTaskCount : " +this.getCompletedTaskCount() + "getLargestPoolSize : " + this.getLargestPoolSize() + "getActiveCount : " + this.getActiveCount());
        super.terminated();
        System.out.println("thread terminated");
    }
}
